using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Marlimer.Common;
using Marlimer.Common.Entidades; 

namespace Marlimer.Data.Comercial
{
    public class com_Transportista
    {

        public DataTable getDTTransportista()
        {
            SqlCommand sqlcmd = new SqlCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();

            sqlcmd.CommandText = "spsdtTransportista";
            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcmd.Connection = Session.getConexion();

            da.SelectCommand = sqlcmd;
            da.Fill(ds);

            return ds.Tables[0];
        }


        public DataTable consultaTransportista(int ccod_trans, String craz_soc, int ctip_per, int ctip_docide, String cnum_docide, String cnum_placa, String cnum_licencia, int flg_anulados)
        {
            SqlCommand sqlcmd = new SqlCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();
            sqlcmd.CommandText = "spsConsultaTransportista";
            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcmd.Connection = Session.getConexion();

            sqlcmd.Parameters.Add("@ccod_trans", SqlDbType.Int);
            sqlcmd.Parameters.Add("@craz_soc", SqlDbType.NVarChar, 70);
            sqlcmd.Parameters.Add("@ctip_per", SqlDbType.Int);
            sqlcmd.Parameters.Add("@ctip_docide", SqlDbType.Int);
            sqlcmd.Parameters.Add("@cnum_docide", SqlDbType.NVarChar, 11);
            sqlcmd.Parameters.Add("@cnum_placa", SqlDbType.NVarChar, 10);
            sqlcmd.Parameters.Add("@cnum_licencia", SqlDbType.NVarChar, 15);
            sqlcmd.Parameters.Add("@flg_anulados", SqlDbType.Int);

            sqlcmd.Parameters["@ccod_trans"].Value = ccod_trans;
            sqlcmd.Parameters["@craz_soc"].Value = craz_soc;
            sqlcmd.Parameters["@ctip_per"].Value = ctip_per;
            sqlcmd.Parameters["@ctip_docide"].Value = ctip_docide;
            sqlcmd.Parameters["@cnum_docide"].Value = cnum_docide;
            sqlcmd.Parameters["@cnum_placa"].Value = cnum_placa;
            sqlcmd.Parameters["@cnum_licencia"].Value = cnum_licencia;
            sqlcmd.Parameters["@flg_anulados"].Value = flg_anulados;

            da.SelectCommand = sqlcmd;
            da.Fill(ds);

            return ds.Tables[0];
        }

        public resulMsgError guardar(InfoTransportista trans)
        {
            resulMsgError resul = new resulMsgError(false, "");

            SqlCommand sqlcmd = new SqlCommand();
            sqlcmd.CommandText = "spiaTransportista";
            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcmd.Connection = Session.getConexion();

            sqlcmd.Parameters.Add("@ccod_trans", SqlDbType.Int);
            sqlcmd.Parameters.Add("@cape_pat", SqlDbType.NVarChar, 25);
            sqlcmd.Parameters.Add("@cape_mat", SqlDbType.NVarChar, 25);
            sqlcmd.Parameters.Add("@cnombres", SqlDbType.NVarChar, 30);
            sqlcmd.Parameters.Add("@craz_soc", SqlDbType.NVarChar, 70);
            sqlcmd.Parameters.Add("@ctip_per", SqlDbType.Int);
            sqlcmd.Parameters.Add("@ctip_docide", SqlDbType.Int);
            sqlcmd.Parameters.Add("@cnum_docide", SqlDbType.NVarChar, 11);
            sqlcmd.Parameters.Add("@cnum_placa", SqlDbType.NVarChar, 10);
            sqlcmd.Parameters.Add("@cnum_licencia", SqlDbType.NVarChar, 15);
            sqlcmd.Parameters.Add("@cstatus", SqlDbType.NChar, 1);
            sqlcmd.Parameters.Add("@cpc_crea", SqlDbType.NVarChar, 50);
            sqlcmd.Parameters.Add("@cuser_crea", SqlDbType.Int);
            sqlcmd.Parameters.Add("@cmodo", SqlDbType.Int);

            sqlcmd.Parameters["@ccod_trans"].Value = trans.ccod_trans;
            sqlcmd.Parameters["@cape_pat"].Value = trans.cape_pat;
            sqlcmd.Parameters["@cape_mat"].Value = trans.cape_mat;
            sqlcmd.Parameters["@cnombres"].Value = trans.cnombres;
            sqlcmd.Parameters["@craz_soc"].Value = trans.craz_soc;
            sqlcmd.Parameters["@ctip_per"].Value = trans.ctip_per;
            sqlcmd.Parameters["@ctip_docide"].Value = trans.ctip_docide;
            sqlcmd.Parameters["@cnum_docide"].Value = trans.cnum_docide;
            sqlcmd.Parameters["@cnum_placa"].Value = trans.cnum_placa;
            sqlcmd.Parameters["@cnum_licencia"].Value = trans.cnum_licencia;
            sqlcmd.Parameters["@cstatus"].Value = trans.cstatus;
            sqlcmd.Parameters["@cpc_crea"].Value = Session.getComputerName();
            sqlcmd.Parameters["@cuser_crea"].Value = Session.getInfousuario().ccod_user;
            sqlcmd.Parameters["@cmodo"].Value = trans.cmodo;

            try
            {
                sqlcmd.ExecuteNonQuery();
                //verificamos el tipo de mensaje a mostrar
                if (trans.cmodo == 3)
                {
                    resul.message = "Anulado satisfactoriamente";
                }
                else
                {
                    resul.message = "Se guardo satisfactoriamente";
                }
                resul.resul = true;
            }
            catch (Exception ex)
            {
                resul.message = ex.Message;
            }
            return resul;
        }

    }
}
